// src/api/productAPI.js
import http from '@/utils/http'

/**
 * 添加商品信息
 * @param {Object} params - 商品信息对象
 */
export const addProductAPI = (params) => {
  return http.post('/product-client/cms/productInfo/add', params)
}

/**
 * 修改商品信息
 * @param {number} id - 商品ID
 * @param {Object} params - 商品信息对象
 */
export const updateProductAPI = (id, params) => {
  return http.post(`/product-client/cms/productInfo/update?id=${id}`, params)
}

/**
 * 删除商品
 * @param {number} id - 商品ID
 */
export const deleteProductAPI = (id) => {
  return http.post(`/product-client/cms/productInfo/delete?id=${id}`)
}

/**
 * 获取商品详情
 * @param {number} id - 商品ID
 */
export const getProductAPI = (id) => {
  return http.post(`/product-client/cms/productInfo/get?id=${id}`)
}

/**
 * 切换商品状态
 * @param {number} id - 商品ID
 */
export const toggleProductStatusAPI = (id) => {
  return http.post(`/product-client/cms/productInfo/toggleStatus?id=${id}`)
}

/**
 * 根据商品名称模糊匹配
 * @param {string} name - 商品名称
 */
export const searchProductByNameAPI = (name) => {
  return http.post('/product-client/cms/productInfo/searchByName', {}, {
    params: {
      name: name || undefined
    }
  })
}

/**
 * 获取所有商品信息
 */
export const listAllProductsAPI = () => {
  return http.post('/product-client/cms/productInfo/listAll')
}
